Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add address arg for duckdb-server-rust #649

Merged
merged 4 commits into from
Jan 9, 2025

Conversation

kwonoh
Copy link
Contributor

@kwonoh kwonoh commented Jan 9, 2025

Add --address as part of CLI arguments. The default is 127.0.0.1 and if parsing the given value fails, it falls back to Ipv4Addr::LOCALHOST

> ./duckdb-server --help                       
DuckDB Server for Mosaic.

Usage: duckdb-server [OPTIONS] [DATABASE]

Arguments:
  [DATABASE]  Path of database file (e.g., "database.db". ":memory:" for in-memory database) [default: :memory:]

Options:
  -a, --address <ADDRESS>                            HTTP Address [default: 127.0.0.1]
  -p, --port <PORT>                                  HTTP Port [default: 3000]
      --connection-pool-size <CONNECTION_POOL_SIZE>  Max connection pool size [default: 10]
      --cache-size <CACHE_SIZE>                      Max number of cache entries [default: 1000]
  -h, --help                                         Print help
  -V, --version                                      Print version

let addr = SocketAddr::new(
args.address
.parse::<IpAddr>()
.unwrap_or(Ipv4Addr::LOCALHOST.into()),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this actually fall back since you define a default in line 26? I realize this might be a question for all the defaults here. It would be nice to define them only in one place.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The above default value (127.0.0.1) will be used if nothing was passed.
The value in unwrap_or (Ipv4Addr::LOCALHOST.into()) will be used if parse fails. For example, if an invalid IP address was passed like --address 127.0

Copy link
Contributor Author

@kwonoh kwonoh Jan 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to define them only in one place.

I agree. Do you think using global constant variables a good way to achieve this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know about the parse failure case you described. I wonder whether we just want to fail when the parsing of provided or default values fails. That might make things simpler.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just made a change for that. Now, if --address is not provided, it will use default value (only defined in one place), if invalid IP address is provided, it will output the error, not using the default value.

> ./target/release/duckdb-server --address 0.0.0.0 --port 5002
2025-01-09T19:30:34.343971Z  INFO duckdb_server: Creating database in ':memory:'
2025-01-09T19:30:34.351430Z  WARN duckdb_server: No keys for HTTPS found.
2025-01-09T19:30:34.351448Z  INFO duckdb_server: DuckDB Server listening on http://0.0.0.0:5002 and ws://0.0.0.0:5002.
^C

> ./target/release/duckdb-server --port 5002 
2025-01-09T19:30:38.984626Z  INFO duckdb_server: Creating database in ':memory:'
2025-01-09T19:30:38.991219Z  WARN duckdb_server: No keys for HTTPS found.
2025-01-09T19:30:38.991237Z  INFO duckdb_server: DuckDB Server listening on http://127.0.0.1:5002 and ws://127.0.0.1:5002.
^C

> ./target/release/duckdb-server --address 999.999.999.999 --port 5002
error: invalid value '999.999.999.999' for '--address <ADDRESS>': invalid IP address syntax

For more information, try '--help'.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. Should we do the same for the app.rs file (e.g.

dp_path.unwrap_or(":memory:"),
)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated. Added the default values as global constants.

@domoritz domoritz merged commit 3ba3a0e into uwdata:main Jan 9, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants